import { Global, Inject, Injectable, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PrismaClient } from '@prisma/client';

@Global()
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
  @Inject()
  configService: ConfigService;
  async onModuleInit() {
    await this.$connect();
  }
}

export const service = new PrismaClient().$extends({
  name: 'href',
  result: {
    file: {
      href: {
        nedds: {
          name: true,
        },
        compute({ name }) {
          return process.env['FILE_ACCESS_PATH'] + '/' + name;
        },
      },
    },
  },
});
